home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / pp / pp-6.0 / Tools / ckor / rfc2or.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-18  |  1.8 KB  |  102 lines

  1. /* rfc2or.c: Parses an RFC address using the tables or, or2rfc and rfc2or */
  2.  
  3. # ifndef lint
  4. static char Rcsid[] = "@(#)$Header: /xtel/pp/pp-beta/Tools/ckor/RCS/rfc2or.c,v 6.0 1991/12/18 20:29:26 jpo Rel $";
  5. # endif
  6.  
  7. /*
  8.  * $Header: /xtel/pp/pp-beta/Tools/ckor/RCS/rfc2or.c,v 6.0 1991/12/18 20:29:26 jpo Rel $
  9.  *
  10.  * $Log: rfc2or.c,v $
  11.  * Revision 6.0  1991/12/18  20:29:26  jpo
  12.  * Release 6.0
  13.  *
  14.  */
  15.  
  16.  
  17.  
  18. #include "head.h"
  19. #include "or.h"
  20.  
  21. extern char             or_error[];
  22.  
  23.  
  24.  
  25.  
  26. /* ---------------------  Begin  Routines  -------------------------------- */
  27.  
  28.  
  29.  
  30. main (argc, argv)
  31. int     argc;
  32. char    *argv[];
  33. {
  34.     char    buf[BUFSIZ];
  35.     int     i = 1;
  36.  
  37.     sys_init (argv[0]);
  38.  
  39.     if (or_init() == NOTOK ) {
  40.         printf ("or_init() failed\n");
  41.         exit (1);
  42.     }
  43.  
  44.     if (argc == 1)
  45.         while (gets (buf) != NULL)
  46.             parse_address (buf);
  47.     else
  48.         while (i < argc)
  49.             parse_address (argv[i++]);
  50. }
  51.  
  52.  
  53. /* ---------------------  Static  Routines  ------------------------------- */
  54.  
  55.  
  56.  
  57. static int parse_address (str)
  58. char    *str;
  59. {
  60.     char            rfcbuf [BUFSIZ];
  61.     char            x400buf [BUFSIZ];
  62.     OR_ptr          or = NULLOR;
  63.  
  64.     or_error[0] = x400buf[0] = rfcbuf[0] = '\0';
  65.  
  66.     /* --- Perform the x400 addressing --- */
  67.     if ((or_rfc2or (str, &or) != OK) || (or == NULLOR))
  68.         goto error;
  69.  
  70.     if (isstr (or_error))
  71.         goto error;
  72.  
  73.     or_or2std (or, x400buf, FALSE);
  74.  
  75.     /* --- Perform the rfc822 address parsing --- */
  76.     if (or_or2rfc (or, rfcbuf) == NOTOK)
  77.         goto error;
  78.  
  79.     if (isstr (or_error))
  80.         goto error;
  81.     
  82.     printf ("\n%s -> (x400)   %s\n%-*s -> (rfc822) %s\n",
  83.         str, x400buf, strlen(str), "", rfcbuf);
  84.  
  85.     goto finish;
  86.  
  87.  
  88. error:  ;
  89.     printf ("Address parsing rfc2or failed \nReason : %s\n", or_error);
  90.     if (rfcbuf[0] != '\0')
  91.         printf ("%s -> (rfc822) %s\n", str, rfcbuf);
  92.     if (x400buf[0] != '\0')
  93.         printf ("%s -> (x400) %s\n", str, x400buf);
  94.  
  95.  
  96. finish: ;
  97.     printf ("\n");
  98.     fflush (stdout);
  99.     or_free (or);
  100.     return;
  101. }
  102.